﻿// <copyright file="MenuExtension.cs" company="Clever Software">
// Copyright (c) 2013, 2014 All Right Reserved, http://www.cleversoftware.by
//
// This source is subject to the Microsoft Permissive License.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Clever Software</author>
// <email>info@cleversoftware.by</email>
// <date>2014-02-04</date> 
// <summary>CleverCMS source code</summary>

namespace CleverCMS.Core.Web.Extensions
{
    using System.Text;
    using System.Web.Mvc;
    using System.Collections.Generic;
    using CleverCMS.Cms.Data.Entities;

    public static class MenuExtension
    {

        public static System.Web.Mvc.MvcHtmlString BuildMenu(this HtmlHelper helper, List<CmsMenuItem> menu)
        {
            return new MvcHtmlString(BuildStringMenu(helper, menu));
        }

        private static string BuildStringMenu(HtmlHelper helper, List<CmsMenuItem> menu)
        {
            var sb = new StringBuilder();
            if ((menu != null) && (menu.Count > 0))
            {
                sb.Append("<ul>");
                //foreach (var item in menu)
                //{
                //    sb.Append("<li>");
                //    sb.Append(helper.ActionLink(item.Title, item.NavigateUrl));
                //    sb.Append("</li>");
                //    if ((item.MenuItems != null) && (item.MenuItems.Count > 0))
                //    {
                //        sb.Append("<li>");
                //        sb.Append(BuildStringMenu(helper, item.MenuItems));
                //        sb.Append("</li>");
                //    }
                //}
                sb.Append("</ul>");
            }
            return (sb.ToString());
        }

    }
}